package com.ag.admin.web.tags;

import java.io.IOException;
import java.io.Writer;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.components.Component;
import org.apache.struts2.interceptor.SessionAware;

import com.ag.admin.utils.UserUtil;
import com.opensymphony.xwork2.util.ValueStack;

public class Hello extends Component implements SessionAware {
	private String value;
    private HttpServletRequest request;
    private Map session;
    
    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
    
    public Hello(ValueStack arg0, HttpServletRequest request) {
        super(arg0);
        Map<String,Object> m=arg0.getContext();
        for (String good : m.keySet()) {
			System.out.println("get(good)"+m.get(good));
		}
        request.getSession();
        this.request = request;
    }

    
    public boolean start(Writer writer) {
        boolean result = super.start(writer);
        //request.getSession();
        System.out.println(session==null);
        session.get(UserUtil.USER_SESSION);
        try {
            if (getValue() == null) {
                value = "";
            } else {
                value = "Hello, " + getValue() + "!";
            }

            writer.write(value);
            
        } catch (IOException ex) {
            Logger.getLogger(Hello.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }

	@Override
	public void setSession(Map<String, Object> arg0) {
		this.session=arg0;
		
	}

}
